/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package sys.screen;

import java.io.IOException;
import java.sql.SQLException;
import java.text.NumberFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import sys.bean.ClienteBean;
import sys.bean.ValeMercadoriaBean;
import sys.dao.ClienteDao;
import sys.dao.ValeMercadoriaDao;
import sys.utils.LetterUpper;
import sys.utils.Mensagens;
import sys.utils.Utils;
import static sys.utils.Utils.codCorreto;
import static sys.utils.Utils.escClose;
import static sys.utils.Utils.numParaCalculos;

/**
 *
 * @author Administrador
 */
public class UIAlteraVale extends javax.swing.JDialog {

    ValeMercadoriaBean vale;
    NumberFormat formatoMoeda = NumberFormat.getCurrencyInstance();
    SimpleDateFormat formDataSpacTabela = new SimpleDateFormat("yyMMdd");
    ClienteBean cliente;
    UIVale telaVale;

    /**
     * Creates new form UIAlteraVale
     *
     * @param parent
     * @param modal
     */
    public UIAlteraVale(java.awt.Dialog parent, boolean modal) {
        super(parent, modal);
        initComponents();
        escClose(this);
        setLocationRelativeTo(null);
        telaVale = (UIVale) parent;
        txNovoValor.setEnabled(false);
        txNovoCodigoCliente.setEnabled(false);
        btnBuscaCliente.setEnabled(false);
        txNovoCliente.setEnabled(false);
    }

    public String dataTabelaSpac() {
        String data = "";
        Date dataTabela = Utils.stringToDate(txDataEmissao.getText());

        data = formDataSpacTabela.format(dataTabela);

        return data;
    }

    private void enableOrDisableValor(boolean v) {
        txNovoValor.setEnabled(v);
    }

    private void enableOrDisableClient(boolean v) {
        txNovoCodigoCliente.setEnabled(v);
        txNovoCliente.setEnabled(v);
        btnBuscaCliente.setEnabled(v);
        txNovoCliente.setEnabled(v);
    }

    public void carregaDadosVale(String codVale, String dataTabela) {

        try {
            vale = ValeMercadoriaDao.DadosVale(codVale, dataTabela);

            txVale.setText(codVale);
            txDataEmissao.setText(vale.getDataEmissao());
            txPedido.setText(vale.getPedidoOrigem());
            txTransacao.setText(vale.getnTransacao());
            txVendedor.setText(vale.getUsuario().getNome());
            txCliente.setText(vale.getCliente().getNome());
            txValor.setText(formatoMoeda.format(vale.getvVale()));

            txNovoCliente.setText(vale.getCliente().getNome());
            txNovoCodigoCliente.setText(vale.getCliente().getCodigo());

        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao atualizar dados do vale\n" + ex.getMessage());
        }
    }

    public void preencheCampos() {
        try {
            cliente = ClienteDao.consultaCliente(codCorreto(txNovoCodigoCliente.getText(), 5));
            txNovoCodigoCliente.setText(cliente.getCodigo());
            txNovoCliente.setText(cliente.getNome());
        } catch (SQLException | IOException ex) {
            Mensagens.msgErro("erro ao carregar dados do cliente\n" + ex.getMessage());
        }
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txVale = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txVendedor = new javax.swing.JTextField();
        txDataEmissao = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        txTransacao = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        txPedido = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        txCliente = new javax.swing.JTextField();
        txValor = new javax.swing.JTextField();
        jLabel8 = new javax.swing.JLabel();
        jPanel4 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        txNovoValor = new javax.swing.JTextField();
        jLabel7 = new javax.swing.JLabel();
        txNovoCodigoCliente = new javax.swing.JTextField();
        btnBuscaCliente = new javax.swing.JButton();
        txNovoCliente = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        jPanel5 = new javax.swing.JPanel();
        btnGerar = new javax.swing.JButton();
        btnSair = new javax.swing.JButton();
        cbAlteraCliente = new javax.swing.JCheckBox();
        cbAlteraValor = new javax.swing.JCheckBox();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("REAJUSTAR VALE");

        jPanel1.setBackground(new java.awt.Color(255, 255, 255));

        jPanel2.setBackground(new java.awt.Color(255, 255, 255));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "DADOS DO VALE:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel1.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel1.setText("VALE:");

        txVale.setEditable(false);
        txVale.setBackground(new java.awt.Color(245, 245, 245));
        txVale.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txVale.setForeground(new java.awt.Color(51, 51, 255));
        txVale.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txVale.setBorder(null);

        jLabel2.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel2.setText("VENDEDOR:");

        txVendedor.setEditable(false);
        txVendedor.setBackground(new java.awt.Color(245, 245, 245));
        txVendedor.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txVendedor.setForeground(new java.awt.Color(51, 51, 255));
        txVendedor.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txVendedor.setBorder(null);

        txDataEmissao.setEditable(false);
        txDataEmissao.setBackground(new java.awt.Color(245, 245, 245));
        txDataEmissao.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txDataEmissao.setForeground(new java.awt.Color(51, 51, 255));
        txDataEmissao.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txDataEmissao.setBorder(null);

        jLabel3.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel3.setText("DATA DE EMISSÃO:");

        jLabel4.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel4.setText("TRANSAÇÃO:");

        txTransacao.setEditable(false);
        txTransacao.setBackground(new java.awt.Color(245, 245, 245));
        txTransacao.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txTransacao.setForeground(new java.awt.Color(51, 51, 255));
        txTransacao.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txTransacao.setBorder(null);

        jLabel5.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel5.setText("PEDIDO:");

        txPedido.setEditable(false);
        txPedido.setBackground(new java.awt.Color(245, 245, 245));
        txPedido.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txPedido.setForeground(new java.awt.Color(51, 51, 255));
        txPedido.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txPedido.setBorder(null);

        jLabel6.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel6.setText("CLIENTE:");

        txCliente.setEditable(false);
        txCliente.setBackground(new java.awt.Color(245, 245, 245));
        txCliente.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        txCliente.setForeground(new java.awt.Color(51, 51, 255));
        txCliente.setBorder(null);

        txValor.setEditable(false);
        txValor.setBackground(new java.awt.Color(245, 245, 245));
        txValor.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txValor.setForeground(new java.awt.Color(51, 51, 255));
        txValor.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txValor.setBorder(null);

        jLabel8.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel8.setText("VALOR:");

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(jPanel2Layout.createSequentialGroup()
                            .addComponent(txVendedor, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(txCliente))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel2Layout.createSequentialGroup()
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(txVale, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel2))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel6)
                                .addGroup(jPanel2Layout.createSequentialGroup()
                                    .addComponent(txDataEmissao, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                    .addComponent(txPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(77, 77, 77)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel5)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jLabel8)
                        .addComponent(jLabel4)
                        .addComponent(txValor, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(txTransacao, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txTransacao, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel8, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txValor, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE))
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                                .addGap(0, 0, Short.MAX_VALUE)
                                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                .addComponent(txDataEmissao, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addComponent(txPedido, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addComponent(txVale, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(9, 9, 9)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 11, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txVendedor, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );

        jPanel4.setBackground(new java.awt.Color(255, 255, 255));
        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "NOVOS VALORES:", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Calibri", 0, 10))); // NOI18N

        jLabel9.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel9.setText("NOVO VALOR:");

        txNovoValor.setBackground(new java.awt.Color(245, 245, 245));
        txNovoValor.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txNovoValor.setForeground(new java.awt.Color(204, 0, 204));
        txNovoValor.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txNovoValor.setBorder(null);
        txNovoValor.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txNovoValorKeyReleased(evt);
            }
        });

        jLabel7.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel7.setText("CÓDIGO:");

        txNovoCliente.setDocument(new LetterUpper());
        txNovoCodigoCliente.setBackground(new java.awt.Color(245, 245, 245));
        txNovoCodigoCliente.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txNovoCodigoCliente.setForeground(new java.awt.Color(204, 0, 204));
        txNovoCodigoCliente.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txNovoCodigoCliente.setBorder(null);
        txNovoCodigoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txNovoCodigoClienteActionPerformed(evt);
            }
        });
        txNovoCodigoCliente.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                txNovoCodigoClienteKeyReleased(evt);
            }
        });

        btnBuscaCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find-2.png"))); // NOI18N
        btnBuscaCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuscaClienteActionPerformed(evt);
            }
        });

        txNovoCliente.setDocument(new LetterUpper());
        txNovoCliente.setEditable(false);
        txNovoCliente.setBackground(new java.awt.Color(245, 245, 245));
        txNovoCliente.setFont(new java.awt.Font("Calibri", 1, 12)); // NOI18N
        txNovoCliente.setForeground(new java.awt.Color(204, 0, 204));
        txNovoCliente.setBorder(null);
        txNovoCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                txNovoClienteActionPerformed(evt);
            }
        });

        jLabel10.setFont(new java.awt.Font("Calibri", 0, 11)); // NOI18N
        jLabel10.setText("NOVO CLIENTE:");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel9)
                    .addComponent(txNovoValor, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txNovoCodigoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnBuscaCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 35, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel10)
                    .addComponent(txNovoCliente, javax.swing.GroupLayout.PREFERRED_SIZE, 236, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel9)
                    .addComponent(jLabel7)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(txNovoCliente, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnBuscaCliente, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(txNovoCodigoCliente, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(txNovoValor, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBackground(new java.awt.Color(245, 245, 245));
        jPanel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(204, 204, 204)));

        btnGerar.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnGerar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/find.png"))); // NOI18N
        btnGerar.setText("SALVAR");
        btnGerar.setPreferredSize(new java.awt.Dimension(120, 30));
        btnGerar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnGerarActionPerformed(evt);
            }
        });
        jPanel5.add(btnGerar);

        btnSair.setFont(new java.awt.Font("Calibri", 0, 13)); // NOI18N
        btnSair.setIcon(new javax.swing.ImageIcon(getClass().getResource("/sys/picture/sair.png"))); // NOI18N
        btnSair.setText("SAIR");
        btnSair.setPreferredSize(new java.awt.Dimension(120, 30));
        btnSair.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSairActionPerformed(evt);
            }
        });
        jPanel5.add(btnSair);

        cbAlteraCliente.setBackground(new java.awt.Color(255, 255, 255));
        cbAlteraCliente.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbAlteraCliente.setText("ALTERAR CLIENTE");
        cbAlteraCliente.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbAlteraClienteActionPerformed(evt);
            }
        });

        cbAlteraValor.setBackground(new java.awt.Color(255, 255, 255));
        cbAlteraValor.setFont(new java.awt.Font("Calibri", 0, 12)); // NOI18N
        cbAlteraValor.setText("ALTERAR VALOR");
        cbAlteraValor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbAlteraValorActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 511, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(cbAlteraCliente)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(cbAlteraValor))
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(cbAlteraCliente)
                    .addComponent(cbAlteraValor))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void txNovoCodigoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txNovoCodigoClienteActionPerformed
        if (txNovoCodigoCliente.getText().equals("")) {
            UIPesquisaCliente pCliente = new UIPesquisaCliente(this, true);
            pCliente.setVisible(true);
        } else {
            preencheCampos();
        }
    }//GEN-LAST:event_txNovoCodigoClienteActionPerformed

    private void txNovoCodigoClienteKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txNovoCodigoClienteKeyReleased
        if (txNovoCodigoCliente.getText().equals("")) {
            txNovoCliente.setText("");
        }
    }//GEN-LAST:event_txNovoCodigoClienteKeyReleased

    private void btnBuscaClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnBuscaClienteActionPerformed
        UIPesquisaCliente pCliente = new UIPesquisaCliente(this, true);
        pCliente.setVisible(true);
    }//GEN-LAST:event_btnBuscaClienteActionPerformed

    private void txNovoClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_txNovoClienteActionPerformed

    }//GEN-LAST:event_txNovoClienteActionPerformed

    private void btnGerarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGerarActionPerformed

        String alteracao = "confirme alteração:\n\n";

        /*
         altera
         0 - NADA FOI ALTERADO
         1 - ALTERA APENAS OS DADOS REFERENTE A VALOR
         2 - ALTERA TANTO OS DADOS DO VALOR QUANDO OS DADOS DO CLIENTE 
         */
        double altera = 0;
        double novoValor = 0;
        double antigoValor = Double.parseDouble(numParaCalculos(txValor.getText()));

        if (!txNovoValor.getText().equals("")) {
            novoValor = Double.parseDouble(numParaCalculos(txNovoValor.getText()));
        }

        String antigoCliente = txCliente.getText();
        String novoCliente = txNovoCliente.getText();

        if (novoValor != 0 && novoValor != antigoValor) {
            alteracao += "Antigo Valor.: " + formatoMoeda.format(antigoValor) + "\n"
                    + "Novo Valor...: " + formatoMoeda.format(novoValor) + "\n"
                    + "esta correto\n\n";
            altera += 1;
        }

        if (!antigoCliente.equals(novoCliente)) {
            alteracao += "Antigo cliente.: " + antigoCliente + "\n"
                    + "Novo Cliente...: " + novoCliente + "\nesta correto";
            altera += 2;
        }

        if (alteracao.equals("confirme alteração:\n\n")) {
            if (Mensagens.confirmar(this, "deseja realmente sair sem fazer alterações")) {
                this.dispose();
                telaVale.atualizaTabela();
            }
        } else {
            if (Mensagens.confirmar(this, alteracao)) {
                try {
                    if (altera == 1) {
                        ValeMercadoriaDao.alteraValorVM(novoValor, txVale.getText());
                        ValeMercadoriaDao.alteraTransacaoVM(dataTabelaSpac(), novoValor, txTransacao.getText());
                    }
                    if (altera == 2) {
                        ValeMercadoriaDao.alteraClienteVM(txNovoCodigoCliente.getText(), txVale.getText());
                    }
                    if (altera == 3) {
                        ValeMercadoriaDao.alteraClienteVM(txNovoCodigoCliente.getText(), txVale.getText());
                        ValeMercadoriaDao.alteraValorVM(novoValor, txVale.getText());
                        ValeMercadoriaDao.alteraTransacaoVM(dataTabelaSpac(), novoValor, txTransacao.getText());
                    }
                    telaVale.atualizaTabela();
                } catch (SQLException | IOException ex) {
                    Mensagens.msgErro("erro ao alterar valor do vale\n" + ex.getMessage());
                }
            }
            this.dispose();

        }
    }//GEN-LAST:event_btnGerarActionPerformed

    private void btnSairActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSairActionPerformed
        this.dispose();
    }//GEN-LAST:event_btnSairActionPerformed

    private void txNovoValorKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_txNovoValorKeyReleased
        try {
            txNovoValor.setText(formatoMoeda.format(Double.parseDouble(numParaCalculos(txNovoValor.getText()))));
        } catch (java.lang.ArrayIndexOutOfBoundsException e) {
            //
        }
    }//GEN-LAST:event_txNovoValorKeyReleased

    private void cbAlteraClienteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAlteraClienteActionPerformed
        enableOrDisableClient(cbAlteraCliente.isSelected());
        txNovoCodigoCliente.requestFocus();
    }//GEN-LAST:event_cbAlteraClienteActionPerformed

    private void cbAlteraValorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAlteraValorActionPerformed
        enableOrDisableValor(cbAlteraValor.isSelected());
        txNovoValor.setText(formatoMoeda.format(0));
        txNovoValor.requestFocus();
    }//GEN-LAST:event_cbAlteraValorActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnBuscaCliente;
    private javax.swing.JButton btnGerar;
    private javax.swing.JButton btnSair;
    private javax.swing.JCheckBox cbAlteraCliente;
    private javax.swing.JCheckBox cbAlteraValor;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JTextField txCliente;
    private javax.swing.JTextField txDataEmissao;
    private javax.swing.JTextField txNovoCliente;
    public javax.swing.JTextField txNovoCodigoCliente;
    private javax.swing.JTextField txNovoValor;
    private javax.swing.JTextField txPedido;
    private javax.swing.JTextField txTransacao;
    private javax.swing.JTextField txVale;
    private javax.swing.JTextField txValor;
    private javax.swing.JTextField txVendedor;
    // End of variables declaration//GEN-END:variables
}
